home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / CNetDemo / cnet / sdk / Examples / identdlookup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-04  |  27.1 KB  |  772 lines

  1. /************************************************************************
  2.  *    CNet/3 and CNet/4  C language interface routines and examples     *
  3.  *                                                                      *
  4.  *  copyright © 1996 ZenMetal Software ... this code may be freely      *
  5.  *  distributed to and used by registered CNet owners EXCLUSIVELY.      *
  6.  *  Other distribution is in violation of copyright laws.               *
  7.  ************************************************************************/
  8.  
  9.  
  10. /************************************************************************
  11.  *                          Function prototypes                         *
  12.  ************************************************************************/
  13. void        CallHost( UBYTE c );
  14. void        ShutDown( char *spawn );
  15. void        GetOut( void );
  16. int        intGetOut( void );
  17. void        LoadError( void );
  18.  
  19. void DisplayIdentD( void );
  20.  
  21.  
  22. /************************************************************************
  23.  *                           Global Variables                           *
  24.  ************************************************************************/
  25. struct MsgPort         *replyp;    /* Some communication details ...    */
  26. struct CPort           *cport;
  27. struct CMessage        cmess;
  28. struct MainPort        *myp;        /* Pointer to CNet port--ALL info!    */
  29. struct PortData        *z;
  30. char                     **bm;
  31. struct Library         *CNetBase = NULL;
  32. struct SignalSemaphore *SEM;
  33.  
  34.  
  35.  
  36. /************************************************************************
  37.  *                             Main routine                             *
  38.  ************************************************************************/
  39. void main( int argc, char **argv )
  40. {
  41.     Forbid();
  42.     if(argc > 1) cport = (struct CPort *)FindPort( argv[1] );
  43.     Permit();
  44.  
  45.     if( argc<2 || !(cport) ) {
  46.         printf("This is a CNet C program.\n");
  47.         exit(0);
  48.         }
  49.  
  50.     if( !(replyp = CreatePort( 0,0 )))
  51.         exit(0);
  52.  
  53.     cmess.cn_Message.mn_ReplyPort   = replyp;
  54.     cmess.cn_Message.mn_Length      = sizeof( struct CMessage );
  55.     cmess.cn_Message.mn_Node.ln_Name= "cstuff";
  56.  
  57.     // CNet version check
  58.     if( cport->ack != 30 ) {
  59.         cport->ack = 1;
  60.         LoadError();
  61.         }
  62.  
  63.     cport->ack = 0;
  64.  
  65.     z    = cport->zp;
  66.     myp  = cport->myp;
  67.     SEM  = myp->SEM;
  68.     bm   = z->bm;
  69.  
  70.     if( !(CNetBase = OpenLibrary( "cnet.library", 4 )) ) // <- NOTE version 4 - can be changed to 3 to make compatible with older CNet releases!
  71.         LoadError();
  72.  
  73.     atexit(GetOut); // inserts an exit trap.  When exit() is called, the
  74.                    // code in GetOut() is invoked.
  75.  
  76.     onbreak(intGetOut); // this break trap causes the program to exit when
  77.                   // the program receives a break (CTRL-C) signal
  78.  
  79. /************************************************************************
  80.  *           End of CNet setup - YOUR CUSTOM CODE STARTS HERE           *
  81.  ************************************************************************/
  82.  
  83.     DisplayIdentD();
  84.  
  85.     if(EnterLine(8, ELINE_INPUTBOX, "Socket number to lookup: "))
  86.         {
  87.         short port=-1;
  88.         port=LookupIdentd(atol(z->InBuffer));
  89.         sprintf(z->ABuffer, "Socket %s used by %d\n", z->InBuffer, port);
  90.         PutA();
  91.         }
  92.  
  93. /************************************************************************
  94.  *                         exit back to CNet!
  95.  ************************************************************************/
  96.  
  97.     // note that an exit trap calling GetOut() has been inserted previously to
  98.     // facilitate resource cleanup..
  99.     exit(0);
  100. }
  101.  
  102.  
  103. /**************************************************************************
  104.  *       Routine called if Load error (wrong CNet version, etc,...        *
  105.  **************************************************************************/
  106. void LoadError( void )
  107. {
  108.     if(replyp)
  109.         {
  110.         // Use while(GetMsg(replyp) here to get any pending msgs before deleting port!
  111.         DeletePort( replyp );
  112.         }
  113.     exit(0);
  114. }
  115.  
  116.  
  117.  
  118. /**************************************************************************
  119.  *       An added function to call GetOut() for onbreak() support         *
  120.  **************************************************************************/
  121. int intGetOut( void )
  122. {
  123.     exit(0);
  124.     return 0;
  125. }
  126.  
  127.  
  128. /************************************************************************
  129.  *                           Generic EXIT code                          *
  130.  ************************************************************************/
  131. void GetOut( void )
  132. {
  133.     ShutDown( NULL );
  134.  
  135.     // clean up message ports opened by this door.
  136.     if(replyp)
  137.         {
  138.         // delete the port that CNet doors open for CallHost() messages
  139.         DeletePort( replyp );
  140.         }
  141.  
  142. }
  143.  
  144.  
  145. /**************************************************************************
  146.  *                         another file to run?                           *
  147.  **************************************************************************/
  148. void ShutDown( char *spawn )
  149. {
  150.     /* spawn = full path/file to run */
  151.     if( spawn )
  152.         strcpy( z->CSpawn, spawn );
  153.  
  154.     CallHost( 0 );
  155. }
  156.  
  157.  
  158. void CallHost( UBYTE c )
  159. {
  160.     cmess.command = c;
  161.     PutMsg  ( (struct MsgPort *)cport, (struct Message *)&cmess );
  162.     WaitPort( replyp );
  163.     GetMsg  ( replyp );
  164. }
  165.  
  166. void PutText( char *text )
  167. {
  168.     cmess.arg1 = (ULONG)text;    /* text to print        */
  169.     CallHost( 1 );
  170. }
  171.  
  172. void PutA( void )
  173. {
  174.     PutText( z->ABuffer );
  175. }
  176.  
  177.  
  178. /**************************************************************************
  179.  *    ENTERLINE FLAGS:                                                    *
  180.  *    Construct by ORing the following bit defines:                       *
  181.  *                                                                        *
  182.  * ie. EnterLine(3, ELINE_ALLCAPS|ELINE_INPOUTBOX, "My Prompt>");         *
  183.  *                                                                        *
  184.  *     FLAGS:                                                             *
  185.  *     ------                                                             *
  186.  *     ELINE_ALLCAPS       = All capitalized                              *
  187.  *     ELINE_FILENAME      = FILENAME.  Don't allow =":; or asterisk      *
  188.  *     ELINE_USEINBUFF     = Begin with existing z.InBuffer               *
  189.  *     ELINE_NOLEADSPACE   = Chop leading spaces                          *
  190.  *     ELINE_CAPWORDSTART  = Force 1st letter of word caps                *
  191.  *     ELINE_RESTWORDLOWER = Force all others lower case                  *
  192.  *     ELINE_NUMBERSONLY   = Numeric input only                           *
  193.  *     ELINE_INPUTBOX      = Print input box (terminated with . )         *
  194.  *     ELINE_ALLOWMCI      = DO allow MCI                                 *
  195.  *     ELINE_HANDLESPECIAL = HANDLES/SPECIAL.  Don't allow ^_`{|}~@       *
  196.  *     ELINE_XSLASHSTART   = Exit for . or / at beginning of line         *
  197.  *     ELINE_XBKSPACESTART = Exit for backspace at beginning of line      *
  198.  *     ELINE_NOOLMS        = Do not allow OLM's to appear while editing   *
  199.  *     ELINE_ALLOWCHAT     = Allow Chat break in at this prompt. COMMAND  *
  200.  *                           PROMPT.                                      *
  201.  *     ELINE_NOSPACES      = Don't allow SPACES                           *
  202.  *     ELINE_NOCURSORMOVE  = DON'T ALLOW MOVEMENT                         *
  203.  *     ELINE_NOSLASHES     = Don't allow forward slash                    *
  204.  *                                                                        *
  205.  *  NOTE: The old "numeric" flag values still work 100% ..                *
  206.  **************************************************************************/
  207. int EnterLine( UBYTE len, ULONG flags, char *prompt )
  208. {
  209.     cmess.arg1 = (ULONG)len;     /* how many chars max to input    */
  210.     cmess.arg2 = (ULONG)flags;   /* flags describing required input handling */
  211.     cmess.arg3 = (ULONG)prompt;  /* text to print before input    */
  212.     CallHost( 2 );               /* result is in z->InBuffer    */
  213.  
  214.     return( (int)strlen( z->InBuffer ));
  215. }
  216.  
  217.  
  218. /**************************************************************************
  219.  *                       Stop until a key is pressed                      *
  220.  **************************************************************************/
  221. char OneKey( void )
  222. {
  223.     CallHost( 3 );
  224.     return( (char)cmess.result );    /* function returns ASCII value of key pressed */
  225. }
  226.  
  227.  
  228. /**************************************************************************
  229.  *
  230.  **************************************************************************/
  231. void EnterPassword( UBYTE len )
  232. {
  233.     cmess.arg1 = (ULONG)len;    /* max number of characters */
  234.     CallHost( 4 );
  235. }
  236.  
  237. /**************************************************************************
  238.  *                 Check z->InBuffer for Chat, OLM, etc                   *
  239.  **************************************************************************/
  240. long CommonCommands( void )
  241. {
  242.     CallHost( 5 );
  243.     return( (long)cmess.result );
  244. }
  245.  
  246.  
  247. /**************************************************************************
  248.  *
  249.  **************************************************************************/
  250. UBYTE ReadFile( char *path, UBYTE flags )
  251. {
  252.     cmess.arg1 = (ULONG)path;
  253.     cmess.arg2 = (ULONG)flags;          /* 1 = print File Not Found */
  254.     CallHost( 6 );
  255.     return( (UBYTE)cmess.result );      /* returns FALSE if File Not Found */
  256. }
  257.  
  258. /**************************************************************************
  259.  *        Sets the "Action" or "Where" field for the user's port          *
  260.  *      ** remember to retain and restore the previous z->DOING **        *
  261.  **************************************************************************/
  262. void SetDoing( char *what )
  263. {
  264.     cmess.arg1 = (ULONG)what;
  265.     CallHost( 7 );
  266. }
  267.  
  268.  
  269. /**************************************************************************
  270.  *Invokes the CNet editor according to user's preference of line or Visual*
  271.  **************************************************************************/
  272. void CallEditor( short max, short inlines )
  273. {
  274.     cmess.arg1 = (ULONG)max;    /* Maximum number of lines (250)*/
  275.     cmess.arg2 = (ULONG)inlines;    /* TRUE/FALSE use existing _edbuff? */
  276.     CallHost( 8 );
  277. }
  278.  
  279. /**************************************************************************
  280.  *             Read text file with MCI/graphic interpretation             *
  281.  **************************************************************************/
  282. UBYTE ReadGraphics( char *path, char flags )
  283. {
  284.     cmess.arg1 = (ULONG)path;
  285.     cmess.arg2 = (ULONG)flags;    /* 1 = print File Not Found    */
  286.     CallHost( 9 );
  287.     return( (UBYTE)cmess.result );        /* FALSE if File Not Found    */
  288. }
  289.  
  290. /**************************************************************************
  291.  *  Construct a date in CNet format - like that seen in the port titlebar *
  292.  **************************************************************************/
  293. void MakeDate( struct IsDate *date, char *output )
  294. {
  295.     cmess.arg1 = (ULONG)date;
  296.     cmess.arg2 = (ULONG)output;
  297.     CallHost( 10 );
  298. }
  299.  
  300.  
  301. /**************************************************************************
  302.  *                     Load userdata for account "id"                     *
  303.  **************************************************************************/
  304. UBYTE ReadAccount( short id, struct UserData *user )
  305. {
  306.     cmess.arg1 = (ULONG)id;
  307.     cmess.arg2 = (ULONG)user;
  308.     CallHost( 11 );
  309.     return( (UBYTE)cmess.result );
  310. }
  311.  
  312. /**************************************************************************
  313.  *           Saves an account after editing/changing attributes           *
  314.  **************************************************************************/
  315. UBYTE SaveAccount( struct UserData *user, short id )
  316. {
  317.     cmess.arg1 = (ULONG)user;
  318.     cmess.arg2 = (ULONG)id;
  319.     CallHost( 12 );
  320.     return( (UBYTE)cmess.result );
  321. }
  322.  
  323. /**************************************************************************
  324.  *         add charge amount "a" to charge schedule number "n"            *
  325.  **************************************************************************/
  326. UBYTE AddCharge( short n, short a )
  327. {
  328.     cmess.arg1 = (ULONG)n;
  329.     cmess.arg2 = (ULONG)a;
  330.     CallHost( 13 );
  331.     return( (UBYTE)cmess.result );
  332. }
  333.  
  334. /**************************************************************************
  335.  *
  336.  **************************************************************************/
  337. UBYTE CheckBalance( short n, short a )
  338. {
  339.     cmess.arg1 = (ULONG)n;
  340.     cmess.arg2 = (ULONG)a;
  341.     CallHost( 14 );
  342.     return( (UBYTE)cmess.result );
  343. }
  344.  
  345. /***************************************************************************
  346.  * Get text from user.  Results are placed in z.GBuffer[] array of strings *
  347.  * note that there are 16 lines MAX and each line may hold up to 80        *
  348.  * characters                                                              *
  349.  ***************************************************************************/
  350. int EnterText( char firstchar, short maxchars, short perline, short maxlines )
  351. {
  352.     cmess.arg1 = (ULONG)firstchar;
  353.     cmess.arg2 = (ULONG)maxchars;
  354.     cmess.arg3 = (ULONG)perline;
  355.     cmess.arg4 = (ULONG)maxlines;
  356.     CallHost( 15 );
  357.     return( (int)cmess.result );
  358. }
  359.  
  360. /**************************************************************************
  361.  *
  362.  **************************************************************************/
  363. long ConferenceWait( short a )
  364. {
  365.     cmess.arg1 = (ULONG) a;
  366.     CallHost( 16 );
  367.     return( (long)cmess.result );
  368. }
  369.  
  370.  
  371. /****************************************************************************
  372.  * Update the current time, load the user's bbstext translation, charges    *
  373.  * If the user has little time remaining, print "you have xx minutes left", *
  374.  * force Events to be checked for pending event execution..                 *
  375.  ****************************************************************************/
  376. void CheckChanges( void )
  377. {
  378.     CallHost( 17 );
  379. }
  380.  
  381.  
  382. /**************************************************************************
  383.  *      Converts a CNet access/range string to a packed LONG value        *
  384.  **************************************************************************/
  385. long ConvertAccess( char *s )
  386. {
  387.     cmess.arg1 = (ULONG)s;
  388.     CallHost( 18 );
  389.     return( (long)cmess.result );
  390. }
  391.  
  392.  
  393. /**************************************************************************
  394.  * return the number of bytes free on device specified by s               *
  395.  * if q==0, the result is displayed to the user by GetFree()              *
  396.  **************************************************************************/
  397. long GetFree( char *s, UBYTE q )
  398. {
  399.     cmess.arg1 = (ULONG)s;
  400.     cmess.arg2 = (ULONG)q;
  401.     CallHost( 19 );
  402.     return( (long)cmess.result );
  403. }
  404.  
  405. /**************************************************************************
  406.  *  Forces CNet to flush/check it's buffers and parse/update the keyboard *
  407.  *  buffers                                                               *
  408.  **************************************************************************/
  409. void CheckFlowControl( void )
  410. {
  411.     CallHost( 21 );
  412. }
  413.  
  414. /**************************************************************************
  415.  * list the contents of a directory (the user will be prompted for        *
  416.  * directory name).                                                       *
  417.  *                                                                        *
  418.  * options: a = allow selection of files to user's select list            *
  419.  *                                                                        *
  420.  *          b = 1: select and download immediately                        *
  421.  *              2: allow wildcard pattern                                 *
  422.  *                                                                        *
  423.  *          c = list files newer than the date specified by c             *
  424.  *              c is a properly filled out Cnet IsDate structure          *
  425.  **************************************************************************/
  426. long ListDir( UBYTE a, UBYTE b, struct IsDate *c )
  427. {
  428.     cmess.arg1 = (ULONG)a;
  429.     cmess.arg2 = (ULONG)b;
  430.     cmess.arg3 = (ULONG)c;
  431.     CallHost( 22 );
  432.     return( (long)cmess.result );
  433. }
  434.  
  435.  
  436. /**************************************************************************
  437.  * Read the next base/udbase message                                      *
  438.  **************************************************************************/
  439. UBYTE Rnext( void )
  440. {
  441.     CallHost( 24 );
  442.     return( (UBYTE)cmess.result );
  443. }
  444.  
  445. /***************************************************************************
  446.  * Parse the contents of z->InBuffer into z->pitems.  Parses up to numargs *
  447.  * items                                                                   *
  448.  ***************************************************************************/
  449. void ParseCommandLine( UBYTE numargs )
  450. {
  451.     cmess.arg1 = (ULONG)numargs;
  452.     CallHost( 25 );
  453. }
  454.  
  455.  
  456. /**************************************************************************
  457.  *  Takes the contents of z->InBuffer and searches for a matching command *
  458.  *  in menu "num" of BBSMENU.                                             *
  459.  **************************************************************************/
  460. short FindCommand( short num )
  461. {
  462.     cmess.arg1 = (ULONG) num;
  463.     CallHost( 26 );
  464.     return( (short)cmess.result );
  465. }
  466.  
  467. /**************************************************************************
  468.  * Open the filename specified by a, seek to position b in the file       *
  469.  * and display the contents of the file from point b to EOF               *
  470.  **************************************************************************/
  471. void ReadMessagePoint( char *a, long b )
  472. {
  473.     cmess.arg1 = (ULONG) a;
  474.     cmess.arg2 = (ULONG) b;
  475.     CallHost( 27 );
  476. }
  477.  
  478. /**************************************************************************
  479.  * Use the CNet editor to edit the file specified by "file"               *
  480.  **************************************************************************/
  481. void EditMessage( char *file )
  482. {
  483.     cmess.arg1 = (ULONG) file;
  484.     CallHost( 28 );
  485. }
  486.  
  487. /***************************************************************************
  488.  * Load the text from the file-handle given and insert it into the current *
  489.  * port's editor file                                                      *
  490.  ***************************************************************************/
  491. void LoadText( BPTR fh )
  492. {
  493.     cmess.arg1 = (ULONG) fh;
  494.     CallHost( 29 );
  495. }
  496.  
  497.  
  498. /**************************************************************************
  499.  *    1000000 mics = 1 second                                                *
  500.  **************************************************************************/
  501. char WaitForInput( long mics )
  502. {
  503.     cmess.arg1 = (ULONG) mics;
  504.     CallHost( 31 );
  505.     return( (char)cmess.result );
  506. }
  507.  
  508.  
  509. /**************************************************************************
  510.  *                       Select and download a file.                      *
  511.  *                                                                        *
  512.  * file  = full path/filename                                             *
  513.  *                                                                        *
  514.  * flags = 0 -> select without immediate download                         *
  515.  *       = 1 -> select and download immediately                           *
  516.  *                                                                        *
  517.  * flag values below are new for v4.11                                    *
  518.  *                                                                        *
  519.  *       = 2 -> delete file after downloading/no immediate download       *
  520.  *       = 3 -> delete file after downloading/download immediate.         *
  521.  **************************************************************************/
  522. UBYTE SelectAndDownload( char *file, UBYTE flags )
  523. {
  524.     cmess.arg1 = (ULONG)file;
  525.     cmess.arg2 = (ULONG)flags;
  526.     CallHost( 39 );
  527.     return( (UBYTE)cmess.result );
  528. }
  529.  
  530.  
  531. /**************************************************************************
  532.  * file: the ".vde" filename, without the ".vde"!                         *
  533.  * data: pointer to the structure you are going to edit                   *
  534.  * size: structure length in bytes                                        *
  535.  *                                                                        *
  536.  * returns: TRUE  if structure has been changed                           *
  537.  *          FALSE otherwise                                               *
  538.  **************************************************************************/
  539. short VisualDataEditor( char *file, void *data, long size )
  540. {
  541.     cmess.arg1 = (ULONG)file;
  542.     cmess.arg2 = (ULONG)data;
  543.     cmess.arg3 = (ULONG)size;
  544.     CallHost( 40 );
  545.     return( (short)cmess.result );
  546. }
  547.  
  548. /**************************************************************************
  549.  * In preparation for an ExtUpload, this function                         *
  550.  * sets the minimum number of free bytes to maintain on the    drive.        *
  551.  **************************************************************************/
  552. void ExtSetMinFree( long free )
  553. {
  554.     cmess.arg1 = (ULONG)free;
  555.     CallHost( 42 );
  556. }
  557.  
  558.  
  559. /**************************************************************************
  560.  * In preparation for an ExtDownload or an ExtUpload, this function       *
  561.  * sets the protocol to be used.  If you send NULL, it will allow the     *
  562.  * user to choose his OWN protocol.                                       *
  563.  *                                                                        *
  564.  * Otherwise, you may select 'a' to be the first letter of a valid        *
  565.  * system protocol (from BBSPROTO file), such as 'x', 'z', etc.           *
  566.  *                                                                        *
  567.  * TRUE will be returned if a protocol is selected and ready, FALSE       *
  568.  * if there is a problem.                                                 *
  569.  **************************************************************************/
  570. UBYTE ExtSetProtocol( char a )
  571. {
  572.     cmess.arg1 = (ULONG)a;
  573.     CallHost( 43 );
  574.     return( (UBYTE)cmess.result );
  575. }
  576.  
  577.  
  578.  
  579. /**************************************************************************
  580.  * This routine allows the user to download the SINGLE file specified     *
  581.  * by the FULL PATH 'args'.                                               *
  582.  *                                                                        *
  583.  *    Currently, NULL is always returned.                                    *
  584.  **************************************************************************/
  585. char *ExtDownload( char *args )
  586. {
  587.     cmess.arg1 = (ULONG)args;
  588.     CallHost( 44 );
  589.     return( (char *)cmess.result );
  590. }
  591.  
  592.  
  593. /**************************************************************************
  594.  * This routine allows the user to upload the file specified by           *
  595.  * 'args'.  The path for uploading will be taken from the path            *
  596.  * in 'args'.  If you do NOT specify a path, the file(s) will             *
  597.  * appear in the user's HOME directory.                                   *
  598.  *                                                                        *
  599.  * Note that with batch protocols like ZMODEM, the filename(s) are        *
  600.  * taken from the header packet information, and may NOT be the           *
  601.  * same as what you have requested the user upload.  For this reason,     *
  602.  * you should have uploads occur in a TEMP directory, and search that     *
  603.  * directory yourself for new files.                                      *
  604.  *                                                                        *
  605.  * Currently, NULL is always returned.                                    *
  606.  **************************************************************************/
  607. char *ExtUpload( char *args )
  608. {
  609.     cmess.arg1 = (ULONG)args;
  610.     CallHost( 45 );
  611.     return( (char *)cmess.result );
  612. }
  613.  
  614. /**************************************************************************
  615.  * Write myp->Key[] to bbs.ukeys in a CNet friendly manner
  616.  * getsem: 0 = do not lock the key semaphore
  617.  *         1 = lock the key semaphore before writing
  618.  *
  619.  * the key semaphore is myp->SEM[1] so, if you have already performed
  620.  * ObtainSemaphore(myp->SEM[1]), then use WriteBBSKeys(0)
  621.  * if you have not locked the semaphore, use WriteBBSKeys(1)
  622.  *
  623.  * notes:
  624.  *
  625.  * if a user's account data is altered, you must also copy the
  626.  * handle, MailID (AKA UUCP ID), Real Name, etc, to myp->Key[AccountNumber]
  627.  *
  628.  * Please see the structure definition for KeyElement4 in users.h to
  629.  * see what data is saved to myp->Key[x]
  630.  *
  631.  * After doing this, the key array must be written to bbs.ukeys.  This
  632.  * function facilitates all the grunt work of writing the key array
  633.  * in the proper size.
  634.  *
  635.  **************************************************************************/
  636. BYTE WriteUKeys( BYTE getsem )
  637. {
  638.     CallHost( 58 );
  639.     return( (BYTE)cmess.result );
  640. }
  641.  
  642. void DoANSI( UBYTE n, USHORT a, USHORT b)
  643. {
  644.     cmess.arg1 = (ULONG)n;
  645.     cmess.arg2 = (ULONG)a;
  646.     cmess.arg3 = (ULONG)b;
  647.     CallHost( 59 );
  648.     return;
  649. }
  650.  
  651. void DoANSIOut( UBYTE n)
  652. {
  653.     cmess.arg1 = (ULONG)n;
  654.     CallHost( 60 );
  655.     return;
  656. }
  657.  
  658.  
  659. /**************************************************************************
  660.  * Print the prompt string passed as "a" and return the user's            *
  661.  * YES or NO equivalent result.  1=YES, 2=NO                              *
  662.  **************************************************************************/
  663. UBYTE PutQ( char *a )
  664. {
  665.     PutText( a );
  666.     return (UBYTE)(z->MCIcreg[0][0]=='1') ;
  667. }
  668.  
  669.  
  670. /**************************************************************************
  671.  * Isn't it obvious enough? ;-)
  672.  **************************************************************************/
  673. void DoReturn( void )
  674. {
  675.     PutText("\n");
  676. }
  677.  
  678.  
  679. /**************************************************************************
  680.  * Create the editor filename used for the current port and place it      *
  681.  * in the string array passed as "path"                                   *
  682.  **************************************************************************/
  683. void MakeEd( char *path )
  684. {
  685.     sprintf( path, "%s_edbuff%d", myp->gc.ZIPpath, z->InPort );
  686. }
  687.  
  688.  
  689. /**************************************************************************
  690.  * Delete the editor file                                                 *
  691.  **************************************************************************/
  692. void DeleteEd( void )
  693. {
  694.     char    filename[80];
  695.  
  696.     MakeEd    ( filename ) ;
  697.     DeleteFile( filename ) ;
  698. }
  699.  
  700. /**************************************************************************
  701.  * Open the file used for the editor and return the filehandle (BPTR)     *
  702.  **************************************************************************/
  703. BPTR OpenEd( long mode )
  704. {
  705.     char    filename[80];
  706.  
  707.     MakeEd( filename );
  708.  
  709.     return Open( filename, mode );
  710. }
  711.  
  712. /**************************************************************************
  713.  * insert the contents of the file belonging to filehandle "fp" into      *
  714.  * the current port's editor file                                         *
  715.  **************************************************************************/
  716. void PrepEditor( BPTR fp )
  717. {
  718.     BPTR    kp;
  719.     char    buff[100];
  720.  
  721.     if( fp ) {
  722.         if( kp = OpenEd( MODE_NEWFILE ) ) {
  723.             while( FGets( fp, buff, 82 ) && buff[0]!=26 )
  724.                    FPuts( kp, buff     ) ;
  725.  
  726.             Close( kp );
  727.         }
  728.     }
  729.     else    DeleteEd();
  730. }
  731.  
  732. /**************************************************************************
  733.  * Save the contents of the current port's editor file into the file      *
  734.  * belonging to filehandle "fp"                                           *
  735.  **************************************************************************/
  736. void SaveEditor( BPTR fp, UBYTE eof )
  737. {
  738.     BPTR    kp;
  739.     char    buff[100];
  740.  
  741.     if( kp = OpenEd( MODE_OLDFILE ) ) {
  742.         while( FGets( kp, buff, 82 ) && buff[0]!=26 )
  743.                FPuts( fp, buff     ) ;
  744.  
  745.         Close( kp );
  746.  
  747.         DeleteEd();
  748.     }
  749.  
  750.     if( eof ) FPuts( fp, "\032\n" );
  751. }
  752.  
  753.  
  754. void DisplayIdentD( void )
  755. {
  756.     if(myp->MPE->idd)
  757.         {
  758.         struct IdentdData *iddptr=myp->MPE->idd;
  759.         // walk the list of identd data and print specifics
  760.         while(iddptr)
  761.             {
  762.             sprintf(z->ABuffer, "Socket number: %ld, CNet Owner Port: %ld\n", iddptr->socket, iddptr->port);
  763.             PutA();
  764.             iddptr=iddptr->next;
  765.             }
  766.         }
  767.     else
  768.         {
  769.         PutText("No identd entries\n");
  770.         }
  771. }
  772.